Source File
xfn.go
Belonging Package
github.com/ChrisTrenkamp/goxpath/tree
package treeimport ()//Ctx represents the current context position, size, node, and the current filtered resulttype Ctx struct {NodeSetPos intSize int}//Fn is a XPath function, written in Gotype Fn func(c Ctx, args ...Result) (Result, error)//LastArgOpt sets whether the last argument in a function is optional, variadic, or neithertype LastArgOpt int//LastArgOpt optionsconst (None LastArgOpt = iotaOptionalVariadic)//Wrap interfaces XPath function calls with Gotype Wrap struct {Fn Fn//NArgs represents the number of arguments to the XPath function. -1 represents a single optional argumentNArgs intLastArgOpt LastArgOpt}//Call checks the arguments and calls Fn if they are validfunc ( Wrap) ( Ctx, ...Result) (Result, error) {switch .LastArgOpt {case Optional:if len() == .NArgs || len() == .NArgs-1 {return .Fn(, ...)}case Variadic:if len() >= .NArgs-1 {return .Fn(, ...)}default:if len() == .NArgs {return .Fn(, ...)}}return nil, fmt.Errorf("Invalid number of arguments")}
![]() |
The pages are generated with Golds v0.6.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |